#!/bin/bash

# ----------------------------------------------------------------------
# Filename:   ProOwner.sh
# Version:    1.0
# Date:       2013/12/12
# Author:     huijing.hei
# Email:      huijing.hei@cs2c.com.cn
# Summary:    03系统安全功能-07身份鉴别-07测试系统进程的行为可以追溯到当前服务的要求者用户
# Notes:       ***
# Copyright:    China Standard Software Co., Ltd.
# History：     
#             Version 1.0, 2013/12/12
#             - list process owner
# ----------------------------------------------------------------------

##! @TODO: setup sshd
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure

function DoSetup()
{
    #trap DoCleanup EXIT INT 

    IsRoot
    EchoResult "root"

    CheckServiceExists sshd
    EchoResult "check service"

    while true; do
        netstat -nltp | grep sshd
        if [ $? -eq 0 ]; then
            EchoResult "sshd start"
            break
        else
            StartDaemon sshd
        fi
    done

}

##! @TODO: check process owner
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure
function DoTest()
{
    ps -U root -u root u | grep sshd | grep -v grep
    EchoResult "process owner is root"

}


# include lib files

if [ -z "$SFROOT" ]
then
    echo "SFROOT is null, pls check"
    exit 1
fi

. ${SFROOT}/lib/Echo.sh
. ${SFROOT}/lib/Check.sh
. ${SFROOT}/lib/NetOps.sh
. ${SFROOT}/testcases/Security/lib/UserOps.sh

#export LANG=C

DoSetup
DoTest
EchoResult "testcase: check process owner"
echo ""
